package edu.psu.collegerecommendationhelper;

import java.io.File;
import java.io.IOException;

import model.Customer;

import weka.classifiers.Evaluation;
import weka.classifiers.bayes.NaiveBayesUpdateable;
import weka.core.Instance;
import weka.core.Instances;
import weka.core.converters.CSVLoader;

public class WekaToolUtility {

	public NaiveBayesUpdateable buildNaiveBayesModel() throws IOException {
		// load data
	    CSVLoader loader = new CSVLoader();
		loader.setFile(new File("/Users/cbarone/Desktop/test100636.csv"));
		Instances structure = loader.getStructure();
			
		if (structure.classIndex() == -1)
			structure.setClassIndex(structure.numAttributes() - 1);
		
		    // train NaiveBayes
	    NaiveBayesUpdateable nb = new NaiveBayesUpdateable();
	    try {
			nb.buildClassifier(structure);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	    Instance current;
	    while ((current = loader.getNextInstance(structure)) != null)
			try {
				nb.updateClassifier(current);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
	
	    // output generated model
	    System.out.println(nb);
	    
		loader.setFile(new File("/Users/cbarone/Desktop/test.csv"));
		Instances test = loader.getStructure();

		 // evaluate classifier and print some statistics
		 Evaluation eval = null;
		try {
			eval = new Evaluation(structure);
			eval.evaluateModel(nb, test);

		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		 System.out.println(eval.toSummaryString("\nResults\n======\n", false));
		 
	    return nb;
	}
	
	public void evaluateTestData(NaiveBayesUpdateable nb, Customer c) {


	}
	
}
